package com.demo.database.mapper;

import org.apache.ibatis.annotations.Param;

/**
 * 部门管理注解SQL动态语句
 * @cuthor luoxiaojiang
 * @createTime 2019年11月07日20:48:48
 * @Verson 1.0.0
 */

public class DepartmentProvider {

    /**
     * 用字符串的方式拼接查询sql返回
     * @param context
     * @return
     */
    public String getQueryAllSql(String context){

        String sql ="select * from t_demo_department where 1=1";
        if (context!= null && !context.equals("")){
            context ="'%"+context+"%'";
            sql += " and department_name like " +context;
        }
        return sql;
    }

    public String getQueryDelSql(@Param("departmentIds") String...departmentIds){

        String sql = "delete from t_demo_department where ";
        if(departmentIds!=null&&departmentIds.length>0) {
            sql += "department_id in(";
            for(int i=0; i<departmentIds.length; i++) {
                if(i>0) {
                    sql += ",";
                }
                sql += departmentIds[i];
            }
            sql += ")";
        } else {
            sql += "1<>1";
        }
        return sql;
    }
}
